<script src="__LAYUI__/layui.js"></script>
<link href="__LAYUI__/css/layui.css" rel="stylesheet"/>

<form class="layui-form layui-form-pane" action="/index/input/addMainEditor">
    <div class="layui-form-item" pane>
        <label class="layui-form-label">作者姓名</label>
        <div class="layui-input-block">
            <input type="text" name="authorName" required lay-verify="required" placeholder="请输入作者姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" pane>
        <label class="layui-form-label">工作单位</label>
        <div class="layui-input-block">
            <input type="text" name="authorObject" required lay-verify="required" placeholder="请输入工作单位" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" pane>
        <label class="layui-form-label">作者简介</label>
        <div class="layui-input-block">
            <textarea name="authorAbout" required lay-verify="required" placeholder="请输入作者简介" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-upload">
        <label class="layui-form-label">作者照片</label>
        <button type="button" class="layui-btn layui-btn-normal" id="card">选择文件</button>
        <button type="button" class="layui-btn" id="up">开始上传</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo1">
            <p id="demoText"></p>
        </div>
    </div>



    <div class="layui-form-item" pane>
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <input type="hidden" name="author_level" value="{$author_level}">
    <input type="hidden" name="book_id" value="{$book_id}">
    <input id="url" type="hidden" name="url">
</form>
<script>
    layui.use(['upload','form','jquery'],function () {
        var $ = layui.$
            ,upload= layui.upload;
        upload.render({
            elem: '#card'
            ,url: '/index/input/upload'
            ,auto: false
            ,bindAction:'#up'
            ,size: 60 //限制文件大小，单位 KB
            ,done: function(res){
                $('#demo1').attr('src', res.msg.saveName); //图片链接（base64）
                $('#url').val(res.msg.saveName);
            }
        });

        var form = layui.form;

        form.on('submit(demo1)', function(data){
            $.post('/index/input/addMainEditor',data.field,function (res) {
                layer.msg(res.msg, {
                    icon: 1,
                    time: 3000 //2秒关闭（如果不配置，默认是3秒）
                });
                if(res.code){
                    parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            })

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>